import os
import pytest
import uiautomator2 as u2
from common.conf_handle import myconf
from common.loger_handler import mylog
from page_element.init_app import Int_App



@pytest.fixture(scope='session')
def get_drivers():
    """获取driver，初始化界面"""
    devices = myconf.get("APP", "devices")
    apkname = myconf.get("APP", "apkname")
    os.system(F"adb connect {devices}")
    driver = u2.connect(devices)
    driver.app_start(apkname, wait=True)
    d = Int_App(driver)
    d.InstallApp()                                    # 协助安装
    os.system(F"adb shell pm clear {apkname}")        # 清缓存
    d.SignAPP()                                       # 登录APP
    d.openDebug()                                     # 开启调试模式
    d.open_Manual()                                   # 进入手动飞行
    d.open_simulation()                               # 开启模拟飞行
    mylog.info("=====================初始化完成=======================")
    yield driver